/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ReviewPackage;

import java.sql.*;
import DBManager.DBConnection;
import java.util.Date;

/**
 *
 * @author maconcon
 */
public class ReviewManager {

    public boolean addProduct(Review newProduct) {
        boolean result = false;

        try {
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
            PreparedStatement pstmt =
                    conn.prepareStatement("INSERT INTO reviews(productid,reviews,customerid) values (?,?,?)");

            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, newProduct.getId());
            pstmt.setString(i++, newProduct.getMessage());
            pstmt.setInt(i++, newProduct.getCustomerid());


            //execute SQL statement
            pstmt.executeUpdate();

            result = true;
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }

        return result;
    }

    public int Log(int x, Review addmanager) {
        Date newDate = new java.util.Date();
        int result = 0;

        try {
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();
            java.util.Date time = new java.util.Date();


            String message = "user added" + newDate + "\n" + "Added"
                    + "\n" + addmanager.getMessage() + "\n";
            String message1 = "\nAdded Manager time:" + time;

            PreparedStatement pstmt = conn.prepareStatement("insert into logs(customerid,message) values(?,?)");

            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, x);
            pstmt.setString(i++, message);

            pstmt.executeUpdate();
            result = 1;
            //execute SQL statement


        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        return result;
    }
}
